#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

int main()
{
    int timeNow = time(NULL);
    srand(timeNow);

    int capital = 100;
    cout << "Your capital: 100!" << endl;
    cout << "Game ends when you double it or lose them all." << endl << endl;

    int playerGuess;
    int compNumber;
    do {
        int bet; //залог на играча
        do {
            cout << "How much do you want to bet: ";
            cin >> bet;
            if (bet > capital)
            {
                cout << "You don't have so much to bet" << endl;
            }
            if (bet < 0 || bet > 40)
            {
                cout << "Bet can be only between 0 and 40" << endl;
            }
        } while (bet < 0 || bet > 40 || bet > capital);
        cout << "You bet " << bet << endl;
        cout << "Guess 0 or 1: ";
        cin >> playerGuess;
        compNumber = rand() % 2;
        cout << "The computer number is " << compNumber << endl;
        if(playerGuess == compNumber)
        {
            cout << "You won " << bet << endl;
            capital += bet; // равносилно на capital = capital + bet;
        }
        else
        {
            cout << "You lose " << bet << endl;
            capital -= bet; //capital = capital -bet;
        }

        cout << "You now have " << capital <<"!" << endl << endl<< endl;
    } while (capital > 0 && capital < 200);

    if(capital == 0)
    {
        cout << "You lost the game!";
    }
    else
    {
        cout << "YOU WON THE GAME!";
    }
    return 0;
}
